package tako.wisers.com.android.apis.item;

import tako.wisers.com.android.apis.util.BitmapUtils;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

public abstract class BaseItem implements Parcelable {

	protected String mActivity;
	protected String mTitle;
	protected Bitmap mBitmap;
	protected String mOwner;
	protected String mKeyword;

	@Override
	public abstract int describeContents();

	@Override
	public abstract void writeToParcel(Parcel dest, int flags);

	public String getActivity() {
		return mActivity;
	}

	public void setActivity(String activity) {
		mActivity = activity;
	}

	public String getTitle() {
		return mTitle;
	}

	public void setTitle(String title) {
		mTitle = title;
	}

	public Bitmap getBitmap() {
		return mBitmap;
	}

	public void setBitmap(Bitmap bitmap) {
		mBitmap = bitmap;
	}

	public void setBitmap(String bitmapURL) {
		new LoadBitmapThread(bitmapURL, BitmapUtils.GROUP_BITMAP, bitmapURL);
	}

	class LoadBitmapThread extends Thread {
		private String url;

		public LoadBitmapThread(String urlStr, ThreadGroup group_bitmap, String viewID) {
			super(group_bitmap, viewID);
			this.url = urlStr;
			start();
		}

		@Override
		public void run() {
			mBitmap = new BitmapUtils().loadBitmap(url);
		}
	}

	public String getOwner() {
		return mOwner;
	}

	public void setOwner(String owner) {
		mOwner = owner;
	}

	protected void baseWriteToParcel(Parcel parcel, boolean useImage) {
		parcel.writeString(mTitle);
		parcel.writeString(mOwner);
		parcel.writeString(mActivity);
		parcel.writeString(mKeyword);
		if (useImage) {
			mBitmap.writeToParcel(parcel, 0);
		}
	}

	protected void baseReadFromParcel(Parcel in, boolean useImage) {
		mTitle = in.readString();
		mOwner = in.readString();
		mActivity = in.readString();
		mKeyword = in.readString();
		if (useImage) {
			mBitmap = Bitmap.CREATOR.createFromParcel(in);
		}
	}

	public String getKeyword() {
		return mKeyword;
	}

	public void setKeyword(String keyword) {
		this.mKeyword = keyword;
	}

}
